/*
 * @Author: ✨Fireflx 
 * @Date: 2022-02-14 17:58:51 
 * @Last Modified by: ✨Fireflx
 * @Last Modified time: 2022-02-15 09:36:08
 */

const { User } = require("../models")
const { add, update, del, find, findOne } = require('../utils/crud')


const userAdd = async (ctx) => {
    const { username = '', pwd = '' } = ctx.request.body;
    await add(User, ctx, { username, pwd });
}

const userUpdate = async (ctx) => {
    const { _id = '', username = '', pwd = '' } = ctx.request.body;
    await update(User, ctx, { _id }, {
        username,
        pwd
    })
}

const userDel = async (ctx) => {
    const { _id = '' } = ctx.request.body;
    await del(User, ctx, { _id })
}

const userFind = async (ctx) => {
    await find(User, ctx);
}

const userFindOne = async (ctx) => {
    const { _id } = ctx.params;
    await findOne(User, ctx, { _id })
}

module.exports = {
    userAdd,
    userUpdate,
    userDel,
    userFind,
    userFindOne,
}